package com.demo.store.feign;

import com.demo.common.base.pojo.JsonRes;
import com.demo.store.bo.CreateStoreBO;
import com.demo.store.serivce.remote.DispatchRemoteUserMainService;
import com.demo.store.vo.StoreMainVO;
import com.demo.store.converter.StoreMainConverter;
import com.demo.store.entity.StoreMain;
import com.demo.store.service.StoreMainService;
import com.demo.user.bo.CreateUserBO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("storeMain")
public class StoreMainFeignClient {
    @Resource
    private StoreMainService storeMainService;
    @Resource
    private StoreMainConverter storeMainConverter;
    @Resource
    private DispatchRemoteUserMainService dispatchRemoteUserMainService;

    @GetMapping("getOneStoreMain")
    public JsonRes<StoreMainVO> getOneStoreMain(@RequestParam Long id) {
        StoreMain oneStoreMain = storeMainService.getOneStoreMain(id);
        StoreMainVO storeMainVO = storeMainConverter.toStoreMainVO(oneStoreMain);
        return JsonRes.ok(storeMainVO);
    }

    @PostMapping("createStore")
    public JsonRes<Void> createStore(@RequestBody CreateStoreBO createStoreBO) {
        StoreMain storeMain = storeMainConverter.toStoreMain(createStoreBO);
        storeMainService.save(storeMain);


        CreateUserBO createUserBO = new CreateUserBO();
        createUserBO.setAge(10);
        createUserBO.setUserId(22121);
        createUserBO.setSex("nan");
        createUserBO.setUsername("haha");
        dispatchRemoteUserMainService.createUser1(createUserBO);
        return JsonRes.ok();
    }

}
